﻿using System;
using System.Windows.Media;
using SilverChart.Configuration;
using SilverChart.Core.Configuration;
using System.Collections.Generic;

namespace SilverChart.UnitTest.Configuration {
    public class MockedConfigurationParser : AbstractConfigurationParser {

        public const String ITEM_VALUE_TITLE = "Title_Value";
        public const String ITEM_DEFAULT_TITLE = "";

        public const String ITEM_VALUE_TITLE_COLOR = "red";
        public readonly static SolidColorBrush ITEM_VALUE_OBJECT_TITLE_COLOR = new SolidColorBrush(Colors.Red);
        public readonly static SolidColorBrush ITEM_VALUE_OBJECT_DEFAULT_TITLE_COLOR = new SolidColorBrush(Configurations.DefaultTitleColor);

        public const String ITEM_VALUE_TITLE_ELEMENTS = "VALUE_ELEMENTS";

        public const String KNOWN_VALUE = "Known_Value";

        public Boolean DoesItemExist = true;

        public override string GetItemValue(string itemName) {
            if (!DoesItemExist) return null;

            if (itemName == Configurations.ITEM_NAME_TITLE) {
                return ITEM_VALUE_TITLE;
            }
            else if (itemName == Configurations.ITEM_NAME_TITLE_COLOR) {
                return ITEM_VALUE_TITLE_COLOR;
            }

            return KNOWN_VALUE;
        }

        protected override ConfigurationItem CreateConfigurationItem(Type type, string itemName) {
            if (!DoesItemExist) return null;

            if (itemName == Configurations.ITEM_NAME_ELEMENTS) {
                MockedConfigurationParser parser = new MockedConfigurationParser();

                ConfigurationItem item = AbstractConfigurationItem.CreateInstance(type, parser);
                parser.Configuration = item;
                return item;
            }
            else if (itemName == Configurations.ITEM_NAME_LEGEND) {
                MockedConfigurationParser parser = new MockedConfigurationParser();

                ConfigurationItem item = AbstractConfigurationItem.CreateInstance(type, parser);
                parser.Configuration = item;
                return item;
            }
            return null;
        }

        protected override IList<ConfigurationItem> CreateConfigurationCollectionItem(Type type, string itemName) {
            if (!DoesItemExist) return null;

            if (itemName == Configurations.ITEM_NAME_ELEMENT) {
                IList<ConfigurationItem> items = new List<ConfigurationItem>();
                for (int i = 0; i < 3; i++) {
                    MockedConfigurationParser parser = new MockedConfigurationParser();
                    ConfigurationItem item = AbstractConfigurationItem.CreateInstance(type, parser);
                    parser.Configuration = item;
                    items.Add(item);
                }
                return items;
            }
            return null;
        }

        protected override IList<string> GetItemValues(string itemName) {
            throw new NotImplementedException();
        }

        protected override bool IsItemSupportCollection(string itemName) {
            if (!DoesItemExist) return false;
            return itemName == Configurations.ITEM_NAME_ELEMENT;
        }
    }
}
